package com.test.xshang.annotation;

import java.lang.reflect.Method;

/**
 * @BelongsProject: simpleframework
 * @BelongsPackage: com.xshang.annotation
 * @Author: xshang
 * @CreateTime: 2023-06-24  20:28
 * @Description: TODO
 * @Version: 1.0
 */
public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, InstantiationException, IllegalAccessException {
        Class<?> clazz = Class.forName("com.test.xshang.annotation.AnnotationDemo");

        AnnotationDemo instance = (AnnotationDemo) clazz.newInstance();

        Method[] declaredMethods = clazz.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            if (declaredMethod.isAnnotationPresent(TestAnnotation.class)) {
                TestAnnotation annotation = declaredMethod.getAnnotation(TestAnnotation.class);
                declaredMethod.setAccessible(true);
                instance.setValue(annotation.value());
            }
        }

        System.out.println(instance);
        instance.test();

    }
}
